/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backend;

import java.util.Map;
import java.util.TreeMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 *
 * @author MASTER
 */
public class Languages {

    public Languages() {
    }

    public static Map<String,Language> getList() throws Exception {

        Map<String,Language> resp=new TreeMap<String,Language>();

        Connection.setServiceUrl("http://eiffel.itba.edu.ar/hci/service/Common.groovy");

            Document dom = Connection.connect("GetLanguageList", "GET", null );
            NodeList nodes = dom.getElementsByTagName("language");

            for (int i = 0; i < nodes.getLength(); i++) {

                Element e = (Element) nodes.item(i);
                int id = new Integer(e.getAttribute("id"));
                String name= ((e.getElementsByTagName("code")).item(0)).getTextContent();
                String code= ((e.getElementsByTagName("name")).item(0)).getTextContent();

                Language lan= new Language(id,name,code);

                resp.put(name,lan);
            }
            return resp;
    }
}
